package deepr.entity;

import deepr.exception.DeeprException;
import lombok.Data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
public class DeeprRequest {

  private String object;
  private String[] select = new String[]{};
  private Map<String, String[]> match = new HashMap<>();
  private Map<String, String[]> optional = new HashMap<>();
  private List<Map<String, Object>> filter = new ArrayList<>();
  private Integer page = 1;
  private Map<String, Object> params = new HashMap<>();
  private String[] orderBy;
  private boolean readMaster = false;
  private int pageSize = 20;

  public void valid() throws DeeprException {
    if (object == null)
      throw new DeeprException("request object is null");
    if (select.length == 0)
      throw new DeeprException("select length must gt 0");
    if (page >= 999)
      throw new DeeprException("page size too big");
  }

  public void setReadMaster() {
    readMaster = true;
  }

  public boolean getReadMaster() {
    return readMaster;
  }


//  public void convertFilter(List<Map<String, Object>> list) {
//    int i = 0;
//    Map<String, Object>[] f = new HashMap[list.size()];
//    for (Map<String, Object> e : list) {
//      f[i] = e;
//      i++;
//    }
//    filter = f;
//  }

}
